const SqlQuery = reqlib('/lib/sqlquery.js');
// // 导出模块对象
module.exports = {
    // 分页分类获取作品列表
	get_category_art: async (ctx, next) => {
        const { category,pageSize,pageNum} = ctx.request.body
        if(category == '全部'){
            let {startPage , endPage} = await ctx.service.utils.paging(ctx)
            let [artRes] = await ctx.db.query('select * from art  limit ?,?' ,[startPage , endPage])
            ctx.body = {
                code:200,
                msg:'获取成功',
                artList:artRes
            }
        }else{
            let {startPage , endPage} = await ctx.service.utils.paging(ctx)
            let [artRes] = await ctx.db.query('select * from art where art_category=? limit ?,?' ,[category,startPage , endPage])
            ctx.body = {
                code:200,
                msg:'获取成功',
                artList:artRes
            }
        }
    },
    // 分页分类获取作品列表
	search_id_art: async (ctx, next) => {
        const { id} = ctx.request.body
        let [artRes] = await ctx.db.query('select * from art where id=?' ,[id])
        ctx.body = {
            code:200,
            msg:'获取成功',
            art:artRes
        }
    },
    // 根据作品名字搜索作品
    search_art_by_name: async (ctx, next) => {
        const { keyWords } = ctx.request.body
        let {startPage , endPage} = await ctx.service.utils.paging(ctx)
        let [artRes] = await ctx.db.query(`select * from art where art_name like "%${keyWords}%" limit ?,?` ,[startPage , endPage])
        ctx.body = {
            code:200,
            msg:'获取成功',
            artList:artRes
        }
    },
    getcategory: async (ctx, next) => {
        let [artRes] = await ctx.db.query(`select * from category`)
        ctx.body = {
            code:200,
            msg:'获取成功',
            categoryList:artRes
        }
    }
}